package com.ghbank.rdws.auth.util;

import java.util.Date;

import org.apache.commons.lang3.time.FastDateFormat;

import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.hash.Hashing;

/**
 * 
 * @author liuxudong
 * @date 2019年3月22日
 */
public class TokenUtils {
    private static final FastDateFormat TIMESTAMP_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss");
    private static final Joiner KEY_JOINER = Joiner.on("|");

    public static String generateFunctionToken(String functionId, Date generationTime, String functionTokenSalt) {
        return Hashing.goodFastHash(128)
            .hashString(KEY_JOINER.join(functionId, TIMESTAMP_FORMAT.format(generationTime), functionTokenSalt),
                Charsets.UTF_8)
            .toString();
    }
    
    public static void main(String[] args) {
        String token = generateFunctionToken("000100010001",new Date(),"rtds-assetf-info");
        System.out.println(token);
    }
}
